<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>融资筛选列表</title>
<style type="text/css">
    .searchArea .fieldBox .label{width: 80px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;}
</style>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
          <div class="fieldBox" >
                <div class="label">融资基数</div>
                <div class="field">
                	 <select name="fncCrdnlt" id="fncCrdnlt" data-value="${infoVO.fncCrdnlt}" validate="{required:true,select: true}" ligerui="width: 200">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${fncCrdnltList }" var="fc">
                     		<option value="${fc.key }">${fc.value }</option>
                        </c:forEach>
                	</select>
                   <span class="requiredSymbol">*</span>
                </div>
            </div> 
            <div class="fieldBox">
                <div class="label">计划融资日期</div>
                <div class="field">
                   <input name="stdt" id="stdt" type="text" ligerui="width: 90" class="ui-datepicker" value="${infoVO.planStdt}" validate="{required:true,dateISO:true}">
                   <span>—</span>
                   <input name="eddt" id="eddt" type="text" ligerui="width: 90" class="ui-datepicker" value="${infoVO.planEddt}" validate="{dateISO:true}">
                	<span class="requiredSymbol">*</span>
                </div>
            </div>
			<div class="fieldBox">
                <div class="label">客户类型</div>
                <div class="field">
                    <select name="cstTypCd" id="cstTypCd" data-value="${infoVO.cstTypCd}" ligerui="width: 210">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${cstTypCdList }" var="ct">
                     		<option value="${ct.key }">${ct.value }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>        
			<div class="fieldBox">
                <div class="label">所属事业部</div>
                <div class="field">
                	<input name="buOrgCd" id="buOrgCd" type="text" class="ui-textbox" data-value=" " placeholder="--请选择--" ltype="combobox" value="" ligerui="width: 210">
                    <input name="buOrgCdValue" id="buOrgCdValue" type="hidden" value="${infoVO.buOrgCd}">
                    <%-- <select name="buOrgCd" id="buOrgCd" data-value="${infoVO.buOrgCd}" ligerui="width: 210">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${buOrgCdList }" var="bo">
                     		<option value="${bo.key }">${bo.value }</option>
                        </c:forEach>
                    </select> --%>
                </div>
            </div>        
			<div class="fieldBox">
                <div class="label">是否办理抵押</div>
                <div class="field">
                    <select name="isMortgage" id="isMortgage" data-value="${infoVO.isMgt}" ligerui="width: 210">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${isMortgageList }" var="im">
                     		<option value="${im.key }">${im.value }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>        
			<div class="fieldBox">
                <div class="label">是否有保险</div>
                <div class="field">
                    <select name="isInsurance" id="isInsurance" data-value="${infoVO.isInsure}" ligerui="width: 210">
                    	<option value=" " selected="selected">请选择</option>
                         <c:forEach items="${isMortgageList }" var="im">
                     		<option value="${im.key }">${im.value }</option>
                        </c:forEach>
                    </select>
                </div>
            </div>        
            <div class="fieldBox">
                <div class="label">租赁期数</div>
                <div class="field">
                   <input name="leaseTermMinQ" id="leaseTermMinQ" type="text" ligerui="width: 94" class="ui-textbox" value="${infoVO.leaTermB}" validate="{digits:true}">
                   <span>—</span>
                   <input name="leaseTermMaxQ" id="leaseTermMaxQ" type="text" ligerui="width: 94" class="ui-textbox" value="${infoVO.leaTermE}" validate="{digits:true}">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">剩余租赁期数</div>
                <div class="field">
                   <input name="surplusLeaseTermMinQ" id="surplusLeaseTermMinQ" ligerui="width: 94" type="text" class="ui-textbox" value="${infoVO.reLeaTermB}" validate="{digits:true}">
                   <span>—</span>
                   <input name="surplusLeaseTermMaxQ" id="surplusLeaseTermMaxQ" ligerui="width: 94" type="text" class="ui-textbox" value="${infoVO.reLeaTermE}" validate="{digits:true}">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">起租日期</div>
                <div class="field">
                   <input name="stDtQ" id="stDtQ" type="text" ligerui="width: 94" class="ui-datepicker" value="${infoVO.flDateBegin}" validate="{dateISO:true}">
                   <span>—</span>
                   <input name="edDtQ" id="edDtQ" type="text" ligerui="width: 94" class="ui-datepicker" value="${infoVO.flDateEnd}" validate="{dateISO:true}">
                </div>
            </div>
           <div class="fieldBox">
                <div class="label">逾期天数</div>
                <div class="field">
                   <input name="ovdDaysMin" id="ovdDaysMin" type="text" ligerui="width: 94" class="ui-textbox" value="${infoVO.odDateB}" validate="{digits:true}">
                   <span>—</span>
                   <input name="ovdDaysMax" id="ovdDaysMax" type="text" ligerui="width: 94" class="ui-textbox" value="${infoVO.odDateE}" validate="{digits:true}">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">资产包名称</div>
                <div class="field">
                   <input name="assPackNm" id="assPackNm" type="text" class="ui-textbox" value="${infoVO.assPackNm}" ligerui="width: 300">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">支付表号</div>
                <div class="field">
                   <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="" ligerui="width: 200">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox formBtns notRight">
            	<!-- 隐藏融资筛选编号 -->
				<input name="applyId" id="applyId" type="hidden" class="ui-textbox" value="${id}">
				<input name="flag" id="flag" type="hidden" class="ui-textbox" value="${flag}">
				<input name="fncCrdnlt_select" id="fncCrdnlt_select" type="hidden" class="ui-textbox" value="${infoVO.fncCrdnlt}">
           		<span id="searchBtn" class="sq-button-round">查询</span>
                <span id="addBtn" class="sq-button-round" onclick="add();">新增</span>
                <span id="clearBtn" class="sq-button-round" onclick="deleteRow();">删除</span>
                <span id="clearBtnAll" class="sq-button-round" onclick="deleteRowAll();">删除全部</span>
            </div>
          </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid" style="height: 372px;"></div>

<script type="text/javascript">
	var grid = null;
	var applyId = $("#applyId").val();
	var fncCrdnlt = $("#fncCrdnlt_select").val();
	var stdt = $("#stdt").val();
	var eddt = $("#eddt").val();
	$(function () {
		initbuOrgCd();
		initGrid();
		$("#assPackNm").prop("disabled", true);
	});
	
	//所属事业部
	function initbuOrgCd(){
		$("#buOrgCd").ligerComboBox({ 
			url: '<%=path%>/ass/asspackinfo/getbuOrgCd.do',
			ajaxType :'GET',
            slide: false,
            selectBoxHeight: 200,
            valueField: 'key', 
            textField: 'value',
            isMultiSelect: true
        });
		//下拉框赋值
		var _buOrgCdValue = $("#buOrgCdValue").val();
		if(_buOrgCdValue != ""){
			liger.get("buOrgCd").setValue(_buOrgCdValue);
		}
	}
	
	//初始化列表
	function initGrid() {
		var _data = {"id":applyId,"fncCrdnlt":fncCrdnlt,"stdt":stdt,"eddt":eddt};
		var _url = '<%=path%>/ass/asspackinfo/fncPrjPayRltvInfo.do';
		$("#searchBar").ligerForm({validate: true});
    	$("#ligergrid1").ligerGrid({
    		url : _url,
    		method : 'get',
    		parms : _data,
        	columns: [
        		{ display: '资料是否齐全', name: 'crNm', width: 150},
	            { display: '再融资状态', name: 'financingTypeNm', width: 150},
	            { display: '客户名称', name: 'cstNm', width: 150 },
	            { display: '客户类型', name: 'cstTypNm', width: 100 },
	            { display: '合同编号', name: 'contractNumber', width: 150 },
	            { display: '事业部', name: 'buOrgNm', width: 150 },
	            { display: '支付表编号', name: 'paySchId', width: 200 },
	            { display: '还款表状态', name: 'repaymentTypNm', width: 100},
	            { display: '起租日期', name: 'stDate', width: 150, render:renderDate},
	            { display: '可融资金额', name: 'financingAmount', width: 150 }
	        ],
	        pageSize:10, 
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        rownumbers:true,
	        isChecked: f_isChecked, 
	        onCheckRow: f_onCheckRow, 
	        onCheckAllRow: f_onCheckAllRow
    	});
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	}
	
	$("#searchBtn").click(function(event) {
	    var form = new liger.get("searchBar");
		if (!form.valid()) {
			top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
			return false; //验证不通过，不执行以下代码
		}
	    var data = form.getData();
	    for (var name in data){
	       grid.setParm(name,data[name]);
	    };
	   grid.reload();
	});
	
	function f_onCheckAllRow(checked){
        for (var rowid in this.records){
            if(checked)
                addCheckedCustomer(this.records[rowid]['id']);
            else
                removeCheckedCustomer(this.records[rowid]['id']);
        }
    }

    /*
    该例子实现 表单分页多选
    即利用onCheckRow将选中的行记忆下来，并利用isChecked将记忆下来的行初始化选中
    */
    var checkedCustomer = [];
    function findCheckedCustomer(CustomerID){
        for(var i =0;i<checkedCustomer.length;i++){
            if(checkedCustomer[i] == CustomerID) return i;
        }
        return -1;
    }
    function addCheckedCustomer(CustomerID){
        if(findCheckedCustomer(CustomerID) == -1)
            checkedCustomer.push(CustomerID);
    }
    function removeCheckedCustomer(CustomerID){
        var i = findCheckedCustomer(CustomerID);
        if(i==-1) return;
        checkedCustomer.splice(i,1);
    }
    function f_isChecked(rowdata){
        if (findCheckedCustomer(rowdata.id) == -1)
            return false;
        return true;
    }
    function f_onCheckRow(checked, data){
        if (checked) addCheckedCustomer(data.id);
        else removeCheckedCustomer(data.id);
    }
    function f_getChecked(){
        //alert(checkedCustomer.join(','));
    }
    
	 //新增数据
	function add(){
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 1000,
            height:600,
            title : '资产筛选列表',
            url:'<%=path%>/ass/asspackinfo/toListPage.do?id='+applyId,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });	 
	}
	 
	 //删除所选
	function deleteRow(){
		if(checkedCustomer.join(',') != ''){
			$.ligerDialog.confirm('确定删除吗?', function (flag) {
				if(flag == false)return;
				var _payRltvInfo = checkedCustomer.join(',');
				var _url = '<%=path%>/ass/asspackinfo/deletePayRltvInfo.do';
				//发送异步请求校验
				var wait_dialog;
				$.ajax({
					type: 'post',
					dataType: 'json',
					data: {"payRltvInfo":_payRltvInfo,"assPackId":applyId},
					url: _url,
					beforeSend: function(){
				          wait_dialog=top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(msg){
						 wait_dialog.close();
						 if(msg.success == 1){
							top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
							checkedCustomer.splice(0,checkedCustomer.length);
							grid.reload();
						 }else if(msg.success == 0 && !msg.data){//校验不成功,且没有data(id)报错
							top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
						 }
					}
				});
			});
		}else{
			top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
	    	return false; //验证不通过，不执行以下代码
		}
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	
	//刷新列表
	function reloadAssPackInfoList(){
		location.reload();
	}
	//删除所有
	function deleteRowAll(){
			$.ligerDialog.confirm('确定删除所有吗?', function (flag) {
				if(flag == false)return;
				var _url = '<%=path%>/ass/asspackinfo/deletePayRltvInfoAll.do';
				//发送异步请求校验
				var wait_dialog;
				$.ajax({
					type: 'post',
					dataType: 'json',
					data: {"assPackId":applyId},
					url: _url,
					beforeSend: function(){
				          wait_dialog=top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},
					success:function(msg){
						 wait_dialog.close();
						 if(msg.success == 1){
							top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
							grid.reload();
						 }else if(msg.success == 0 && !msg.data){//校验不成功,且没有data(id)报错
							top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
						 }
					}
				});
			});
		
	}	
</script>
</body>
</html>